package org.gdstash.ui;

import org.gdstash.util.GDConstants;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;

public class GDHelpActionListener implements ActionListener {
    private URI uri;

    public GDHelpActionListener(final String filename) {
        final String s = GDConstants.USER_DIR + GDConstants.FILE_SEPARATOR + "doc" + GDConstants.FILE_SEPARATOR + filename;
        final File file = new File(s);
        if (file.exists()) {
            this.uri = file.toURI();
        }
    }

    @Override
    public void actionPerformed(final ActionEvent ev) {
        if (this.uri != null) {
            try {
                Desktop.getDesktop().browse(this.uri);
            } catch (IOException ex) {
            }
        }
    }
}
